/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;

init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  

  checkConfig(config);
  @endpoint = getEndpoint('productcatalog', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }

  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}
model GetApiRequest {
  language?: string(name='Language'),
  reader?: string(name='Reader'),
}

model GetApiResponse = {
  headers: map[string]string(name='headers'),
}

async function getApi(ProductId: string, VersionId: string, ApiId: string, request: GetApiRequest): GetApiResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return getApiWithOptions(ProductId, VersionId, ApiId, request, headers, runtime);
}

async function getApiWithOptions(ProductId: string, VersionId: string, ApiId: string, request: GetApiRequest, headers: map[string]string, runtime: Util.RuntimeOptions): GetApiResponse {
  Util.validateModel(request);
  var query : map[string]any= {};
  if (!Util.isUnset(request.language)) {
    query.Language = request.language;
  }
  if (!Util.isUnset(request.reader)) {
    query.Reader = request.reader;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'GetApi',
    version = '2018-09-18',
    protocol = 'HTTPS',
    pathname = `/products/v1/public/${ProductId}/versions/{VersionId}/apis/{ApiId}`,
    method = 'GET',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'none',
  };
  return callApi(params, req, runtime);
}

model GetProductRequest {
  language?: string(name='Language'),
}

model GetProductResponse = {
  headers: map[string]string(name='headers'),
}

async function getProduct(ProductId: string, request: GetProductRequest): GetProductResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return getProductWithOptions(ProductId, request, headers, runtime);
}

async function getProductWithOptions(ProductId: string, request: GetProductRequest, headers: map[string]string, runtime: Util.RuntimeOptions): GetProductResponse {
  Util.validateModel(request);
  var query : map[string]any= {};
  if (!Util.isUnset(request.language)) {
    query.Language = request.language;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'GetProduct',
    version = '2018-09-18',
    protocol = 'HTTPS',
    pathname = `/products/v1/public/${ProductId}/`,
    method = 'GET',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'none',
  };
  return callApi(params, req, runtime);
}

model ListApisRequest {
  language?: string(name='Language'),
  page?: string(name='Page'),
  limit?: string(name='Limit'),
}

model ListApisResponse = {
  headers: map[string]string(name='headers'),
}

async function listApis(ProductId: string, VersionId: string, request: ListApisRequest): ListApisResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return listApisWithOptions(ProductId, VersionId, request, headers, runtime);
}

async function listApisWithOptions(ProductId: string, VersionId: string, request: ListApisRequest, headers: map[string]string, runtime: Util.RuntimeOptions): ListApisResponse {
  Util.validateModel(request);
  var query : map[string]any= {};
  if (!Util.isUnset(request.language)) {
    query.Language = request.language;
  }
  if (!Util.isUnset(request.page)) {
    query.Page = request.page;
  }
  if (!Util.isUnset(request.limit)) {
    query.Limit = request.limit;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'ListApis',
    version = '2018-09-18',
    protocol = 'HTTPS',
    pathname = `/products/v1/public/${ProductId}/versions/{VersionId}/apis/`,
    method = 'GET',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'none',
  };
  return callApi(params, req, runtime);
}

model ListProductsRequest {
  language?: string(name='Language'),
  page?: string(name='Page'),
  limit?: string(name='Limit'),
}

model ListProductsResponse = {
  headers: map[string]string(name='headers'),
}

async function listProducts(request: ListProductsRequest): ListProductsResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return listProductsWithOptions(request, headers, runtime);
}

async function listProductsWithOptions(request: ListProductsRequest, headers: map[string]string, runtime: Util.RuntimeOptions): ListProductsResponse {
  Util.validateModel(request);
  var query : map[string]any= {};
  if (!Util.isUnset(request.language)) {
    query.Language = request.language;
  }
  if (!Util.isUnset(request.page)) {
    query.Page = request.page;
  }
  if (!Util.isUnset(request.limit)) {
    query.Limit = request.limit;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'ListProducts',
    version = '2018-09-18',
    protocol = 'HTTPS',
    pathname = `/products/v1/public/`,
    method = 'GET',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'none',
  };
  return callApi(params, req, runtime);
}

